const Mock = require('mockjs');
const express = require('express');

const app = express();

function getList(num) {
  return Mock.mock({
    // 属性 list 的值是一个数组，其中含有 1 到 10 个元素
    [`list|${num}`]: [{
      // 属性 id 是一个自增数，起始值为 1，每次增 1
      'id|+1': 1,
      address: "@ctitle(15,25)",
      name: "@ctitle(3, 10)",
      date: "@date('yyyy-mm-dd')"
    }
    ]
  })
}

app.all('*', function (req, res, next) {
  res.header("Access-Control-Allow-Origin", '*');
  res.header('Access-Control-Allow-Methods', 'PUT,GET,POST,DELETE,OPTIONS');
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  next();
});

app.get("/data", function (req, res) {
  const {num} = req.query;
  return res.send(getList(num));
})
const server = app.listen(4000, function () {
  console.log("请求接口！")
})




